<?php

namespace App\Http\Controllers;

use Auth;
use App\User;
use Illuminate\Http\Request;

class EmailController extends Controller
{
    /**
     * @param $token
     */
    public function verify($token)
    {
        // 根据 token 值 验证数据库中是否存在
        $user = User::where('confirmation_token', $token)->first();

        if (is_null($user)) {
            //flash('邮箱证失败', 'danger');
            return redirect('/');
        }

        // 重写 users 表中两个字段的值
        $user->is_active = 1;
        $user->confirmation_token = str_random(40);
        $user->save();

        Auth：：login($user);
        //flash('邮箱证成功', 'success');
        return redirect('/home');
    }
}
